COMPUTER CODES

This folder contains computer codes for the following paper:

A Regularization Corrected Score Method for Nonlinear Regression Models with Covariate Error
David M. Zucker, Malka Gorfine, Yi Li, Mahlet G. Tadesse, and Donna Spiegelman
Published in Biometrics

There are several subfolders, one for each method studied. Below we describe the contents of each subfolder.
Note: We unfortunately are not authorized to share the data used in the data example.

1. RECS Method Subfolder

This subfolder contains three *.zip files, as follows.

a. recs-siml-univ.zip
Contains code for the running simulations on the RECS method (univariate case).
Includes main code written in R and auxiliary code written in Fortran.

Five Fortran routines are called in the R code, as follows:

setup.f:     sets up various matrices needed for the computations
delcmp.f:    computes the average delta vector at the naive beta
scoresoln.f: finds solution to corrected score equation
               (includes routines to compute the corrected score and its jacobian,
                along with an existing nonlinear system solver routine)
scorefn.f:   computes the corrected score function
               (returns either individual-subject results or summary results)
scorejac.f:  computes the jacobian of the score function (summed over subjects)

The subroutine in scoresoln.f incorporates the code in hybrj.f, which contains the nonlinear equation solver.

The above five Fortran routines must be compiled into *.dll files on a Windows system or *.so files on a UNIX system.
To do the compilation on a UNIX system with R installed, use the following command: R CMD SHLIB <filename>.f .

The R code also uses the following R packages: statmod, orthopolynom, mvtnorm. You will have to install them if they are not
installed already. If you are running on a UNIX system and have installed the packages yourself, you will need to modify the
opening section of the code to point R toward the directory where these packages sit.

b. recs-multiv.zip
Contains code for the running simulations on the RECS method (multivariate case).
Includes main code written in R and auxiliary code written in Fortran.

You will have to compile the Fortran code and install certain R packages, as described above for the univariate simulation code.

c. recs-example.zip
Contains code for running the RECS method on the data example.
Includes main code written in R and auxiliary code written in Fortran.

You will have to compile the Fortran code and install certain R packages, as described above for the univariate simulation code.

2. N-S Method Subfolder

This subfolder contains three R programs, as follows.

a. ns-siml-univ.r: contains R code for running the univariate simulations on the N&S method.
b  ns-siml-multiv.r: contains R code for running the multivariate simulations on the N&S method.
c. ns-simex-example-univ.r: contains R code for running the N&S and SIMEX methods on the data example.

3. SIMEX Method Subfolder

This subfolder contains the following three files:

a. ns-simex-univ.r: contains R code for running the univariate simulations on the SIMEX method and the N&S method
(the code for N&S is the same as that in the N-S Method subfolder).
b. ns-simex-multiv.r: contains R code for running the multivariate simulations on the SIMEX method (along with old,
obsolete code for the N&S method).
c. ns-simex-example-univ.r: contains R code for running the N&S and SIMEX methods on the data example
(this file is identical to the file with the same name in the N-S Method subfolder).

4. H-W Method Subfolder

This folder contains R codes for running the simulations on the Huang and Wang method, along with Fortran subroutines
used in the R code. The main Fortran subroutine is hwdr.f, which must be compiled into a *.dll or *.so file, as described
above for the RECS method. The other Fortran subroutines are all called from this subroutine. The file npc.f contains
Huang and Wang's code for their method, kindly provided by Eugene Huang. The main Fortran subroutine hwdr.f is an
interface between R and Huang and Wang's code. The other Fortran subroutines are public-domain LINPACK routines used
in Huang and Wang's code.

5. MCMC Method Subfolder

This subfolder contains three *.zip files, as follows:

a. MCMC1.zip: contains R code for Scenarios A1, A2, B, and D (univariate). The main codes that need to be called are those named scenarioXX_repx.R.
Note that the names of Scenarios C and D were switched in the revision of the paper, so that codes referring to "Scenario C" are for the scenario
identified as "Scenario D" in the final paper.
- For different error variances, you need to change the variable gamma in the code (e.g., 1 to 0.5)
- For different prior variances, you need to change h.beta=diag(100*beta.var) from 100 to 10
- Because the code takes a while to run, the method was run in batches of 10 replications, with each batch run on a different node
of a computing cluster. For different sets of replications, you need to change run=1 to run=xx (we went from 1 to 10 to get the 100
simulated replications).

b. MCMC2.zip: contains R code for the scenario identified in the final paper as "Scenario C" (multivariate). In a previous version of
the paper, this scenario was called "Scenario D", and this is how it is identified in the code. The main code that needs to be called
is scenarioD1_rep1.R.
- for the different scenarios in D, change scene="D1" to "D2" or "D3" as appropriate
- for different prior variance, change 100 to 10 in h.beta=diag(100*beta.var)
- the simulation replicates were run in batches of 5 on different cluster nodes changing run=1 from 1-20

c. MCMC2.zip: contains R code for Scenario A3. The main code that needs to be called is scenarioA3_rev***.R:
- for different measurement error variances, change gam1, gam2 and gam3
- for different prior variances change h.beta=diag(100*beta.var) from 100 to 10
- sets of 10 replicates were submitted on different cluster nodes, by changing run=xx from 1-10.
